<template>
  <div>
    <i class="iconfont icon-pingjia"  @click.stop="openInvestigate"></i>
    <el-dialog :close-on-click-modal="false" append-to-body modal-append-to-body lock-scroll top="10%" :title="$t('cti.trunSatiTable')" :visible.sync="investigate" class="investigate">
      <template>
        <el-table :data="investData" stripe style="width: 100%" size="mini">
          <el-table-column prop="DisplayName" :label="$t('cti.satiSearch')"></el-table-column>
          <el-table-column :label="$t('public.operate')">
            <template scope="scope">
              <el-button @click.stop="phoneInvestigate(scope.$index)" type="text">{{$t('cti.trunSearch')}}</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </el-dialog>
  </div>
</template>
<script>
  import {isHasFunc} from '@/utils/m7Utils'
  export default {
    name: 'investigate',
    props: ['isCloseInvestigate'],
    data () {
      return {
        investigate: false,
        investData: [] // table数据
      }
    },
    watch: {
      'isCloseInvestigate': 'closeInvestigate'
    },
    methods: {
      openInvestigate () {
        this.investigate = true
        let investData = []
        this.$store.dispatch('getCache', { type: 'investigateList' }).then(resp => {
          console.log(resp)
          console.log('resp-------------------------')
          let investList = resp || []
          if (!isHasFunc('func_investigate_default_option_hide', this.$store.state.session.user)) { // func_investigate_default_option_hide: 隐藏软电话条转满意度调查默认选项
            investData.push({DisplayName: this.$t('cti.defaultSati'), Exten: ''}) // 默认满意度
          }
          if (investList) {
            for (let key in investList) {
              if (!investList[key].SatisfactionGarde || investList[key].SatisfactionGarde !== 'child') {
                investData.push({
                  DisplayName: investList[key].DisplayName,
                  Exten: investList[key].Exten
                })
              }
            }
          }
          this.investData = investData
        })
      },
      phoneInvestigate (index) { // 满意度
        let num = this.investData[index].Exten
        this.$store.dispatch('phoneInvestigate', num)
      },
      closeInvestigate () {
        if (!this.isCloseInvestigate) { // 挂断通话的时候关掉弹窗
          this.investigate = false
        }
      }
    }
  }
</script>
<style lang="stylus" scoped>
  div
    width 100%
    height 100%
  .investigate
    text-align left
</style>

